getOptionsFromElement.js ➔ getOptionsFromElement   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 12
nop 1
dl 0
loc 23
rs 8.5906
1
import optionsFromStrings from "./optionsFromStrings.js";
2
import defaults from "../options/defaults.js";
3
4
function getOptionsFromElement(element){
5
	var options = {};
6
	for(var property in defaults){
7
		if(defaults.hasOwnProperty(property)){
8
			// jsbarcode-*
9
			if(element.hasAttribute("jsbarcode-" + property.toLowerCase())){
10
				options[property] = element.getAttribute("jsbarcode-" + property.toLowerCase());
11
			}
12
13
			// data-*
14
			if(element.hasAttribute("data-" + property.toLowerCase())){
15
				options[property] = element.getAttribute("data-" + property.toLowerCase());
16
			}
17
		}
18
	}
19
20
	options["value"] = element.getAttribute("jsbarcode-value") || element.getAttribute("data-value");
21
22
// Since all atributes are string they need to be converted to integers
23
	options = optionsFromStrings(options);
24
25
	return options;
26
}
27
28
export default getOptionsFromElement;
29